package edu.zzu.mapper;

import edu.zzu.Entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

public interface UserMapper extends Mapper<User> {

    @Select("select password from User where id=#{id}")
    String getPasswordById(Long id);

    @Select("select password from User where tel=#{tel}")
    String getPasswordByTel(String tel);

    @Insert("insert into User values(#{id},#{password},#{name},#{role},#{status},#{tel},#{transNodeId})")
    int saveUser(User user);

    @Select("select count(tel) from User where tel=#{tel}")
    int checkIfUserExistByTel(String tel);

    @Select("select TransNodeId from User where id=#{id}")
    Long getTransNodeIdById(Long id);

    @Select("select id from User where tel=#{tel}")
    Long getIdByTel(String tel);

    @Update("update User set password=#{pwd} where id=#{id}")
    int modifyPassword(@Param("id") Long id, @Param("pwd") String pwd);

    @Select("select * from User where tel=#{tel}")
    User selectUserByTel(String tel);

    @Select("select count(id) from User where transNodeId=#{sourceNode}")
    int selectCountBySourceNode(Long sourceNode);
}
